import fetch from "@/utils/http";
import { MenuAddRequest, MenuResponse, MenuUpdateRequest } from "./menu";
import { getFinallyRoutes } from "@/utils/setRoute";
/**
 * 获取所有菜单
 */
export function getAllMenu() {
  return fetch<MenuResponse[]>("/v1/menu/all", "HR", {
    method: "get"
  });
}
/**
 * 新增菜单
 * @param
 * @returns
 */
export function addMenuItem(data: MenuAddRequest) {
  return fetch("/v1/menu/add", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}
/**
 * 编辑菜单
 * @param data
 * @returns
 */
export function editMenuItem(data: MenuUpdateRequest) {
  return fetch<MenuUpdateRequest>("/v1/menu/update", "MANGMENT", {
    method: "post",
    body: JSON.stringify(data)
  });
}

/**
 * 移除菜单
 * @param id
 */
export function removeMenuItem(menuId: string) {
  return fetch(`/v1/menu/remove/${menuId}`, "MANGMENT", {
    method: "get"
  });
}
/**
 * 获取我的菜单
 * @returns
 */
export function getAsyncRoutes() {
  return fetch<MenuResponse[]>("/v1/menu/my", "HR", {
    method: "post"
  }).then(res => {
    return {
      code: 0,
      data: getFinallyRoutes(res.data)
    };
  });
}
